using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Base;

namespace RelativePath
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
        }

        private void TextBoxDragEnter(object sender, DragEventArgs e)
        {
           // if (e.Data.GetDataPresent(DataFormats.Text))
            if (e.Data != null)
                e.Effect = DragDropEffects.Link;
            else
                e.Effect = DragDropEffects.None; 
        }

        private void TextBoxDragDrop(object sender, DragEventArgs e)
        {
            try
            {
                TextBox textBox = (TextBox)sender;
                textBox.Text = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString();
            }
            catch
            {

            }            
        }

        private void TextBoxTextChanged(object sender, EventArgs e)
        {
            RelativePath.Text = string.Empty;

            if (string.IsNullOrEmpty(BasePath.Text))
                return;

            if (string.IsNullOrEmpty(AbsolutePath.Text))
                return;

            string strBasePath = BasePath.Text.Replace('/', '\\');
            string strFullPath = AbsolutePath.Text.Replace('/', '\\');

            try
            {
                string strRelativePath = PathEx.GetRelativePath(strBasePath, strFullPath);
                RelativePath.Text = strRelativePath.Replace('\\', '/');
            }
            catch(Exception ex)
            {
                RelativePath.Text = ex.Message;
            }            
        }     
    }
}